package geez.widget;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import static geez.widget.Geez.withNameAndId;
import static geez.widget.Geez.withStyle;

public class GFlowPanel<T extends GFlowPanel> extends FlowPanel {

    public T id(String id) {
        withNameAndId(this, id);
        return downcastSelft();
    }

    public T css(String cssClass, String... optionalClasses) {
        withStyle(this, cssClass, optionalClasses);
        return downcastSelft();
    }

    public T append(Widget widget) {
        add(widget);
        return downcastSelft();
    }

    private T downcastSelft() {
        //noinspection unchecked
        return (T) this;
    }

    public T positionAbsolute(int x, int y) {
        DOM.setStyleAttribute(getElement(), "position", "absolute");
        DOM.setStyleAttribute(getElement(), "left", x + "px");
        DOM.setStyleAttribute(getElement(), "top", y + "px");
        return downcastSelft();
    }

    public T hide() {
        setVisible(false);
        return downcastSelft();
    }

    public T show() {
        setVisible(true);
        return downcastSelft();
    }
}
